﻿namespace Communication.Help;

public static class AddressTranslation
{
    /// <summary>
    ///     模拟量存储
    /// </summary>
    /// <param name="register"></param>
    /// <param name="bit"></param>
    /// <returns></returns>
    public static int RegisterAddressTranslation(this int register, int bit)
    {
        //左移 4位刚好可以放 0-15 两个字节长度
        return (register << 4) + bit;
    }

    /// <summary>
    ///     模拟量还原
    /// </summary>
    /// <param name="register"></param>
    /// <returns></returns>
    public static int RegisterAddressRestore(this int register)
    {
        return register >> 4;
    }
}